{extend name="common/base"/}
{block name="style"}
<style>
.layui-table-min th{font-size:13px; text-align:center; background-color:#f8f8f8;}
.layui-table-min td{font-size:13px; padding:6px;text-align:center;}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<div class="body-content">
	<h3 class="h3-title">发票详情</h3>
	<table class="layui-table">
		<tr>
			<td class="layui-td-gray">开票金额(元)</td>
			<td>
				{$detail.amount}
			</td>
			<td class="layui-td-gray">开票类型</td>
			<td>
			{eq name="$detail.invoice_type" value="1"}增值税专用发票{/eq}
			{eq name="$detail.invoice_type" value="2"}增值税普通发票{/eq}
			</td>
			<td class="layui-td-gray">开票主体</td>
			<td>
				{volist name=":get_invoice_subject()" id="vo"}
				{eq name="$vo.id" value="$detail.invoice_subject"}{$vo.title}{/eq}
				{/volist}
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">抬头类型</td>
			<td>
				{eq name="$detail.type" value="1"}企业{/eq}
				{eq name="$detail.type" value="2"}个人{/eq}
			</td>
			<td class="layui-td-gray">开票抬头</td>
			<td>{$detail.invoice_title}</td>
			<td class="layui-td-gray">电话号码</td>
			<td>{$detail.invoice_phone}</td>
		</tr>
		<tr class="invoice-type" {eq name="$detail.type" value="2"}style="display:none"{/eq}>
			<td class="layui-td-gray2">纳税人识别号</td>
			<td>{$detail.invoice_tax}</td>
			<td class="layui-td-gray">开户行</td>
			<td>{$detail.invoice_bank}</td>
			<td class="layui-td-gray">银行账号</td>
			<td>{$detail.invoice_account}</td>
		</tr>
		<tr class="invoice-type" {eq name="$detail.type" value="2"}style="display:none"{/eq}>
			<td class="layui-td-gray2">银行营业网点</td>
			<td>{$detail.invoice_banking}</td>
			<td class="layui-td-gray">地址</td>
			<td colspan="3">{$detail.invoice_address}</td>
		</tr>
		{notempty name="$detail.remark"}
		<tr>
			<td class="layui-td-gray">备注信息</td>
			<td colspan="5">{$detail.remark}</td>
		</tr>
		{/notempty}
		<tr>
			<td class="layui-td-gray">发票状态</td>
			<td colspan="5">
				{if condition="($detail.invoice_status == 0)"}
					<span style="color:#FF5722">审核不通过  【原因：{$detail.check_remark}】</span>
				{elseif condition="($detail.invoice_status == 1)"}
					<span style="color:#009688">审核中</span>
				{elseif condition="($detail.invoice_status == 2)"}
					<span style="color:#1E9FFF">审核通过,待开具</span>
				{elseif condition="($detail.invoice_status == 3)"}
					<span style="color:#1E9FFF">已开具</span>
				{elseif condition="($detail.invoice_status == 10)"}
					<span style="color:#FF5722">已作废</span>
				{/if}
			</td>
		</tr>
		{if condition="$detail.check_time > 0"}
		<tr>
			<td class="layui-td-gray2">审核人</td>
			<td>{$detail.check_admin}</td>
			<td class="layui-td-gray2">审核时间</td>
			<td colspan="3">{$detail.check_time}</td>
		</tr>
		{else/}
		<tr>
			<td class="layui-td-gray2">审核人</td>
			<td colspan="5">{$detail.check_admin}</td>
		</tr>
		{/if}
		{if condition="$detail.open_admin_id > 0"}
		<tr>
			<td class="layui-td-gray2">开票人</td>
			<td>{$detail.open_admin}</td>
			<td class="layui-td-gray2">开票时间</td>
			<td>{$detail.open_time}</td>
			<td class="layui-td-gray2">发票号码</td>
			<td>{$detail.code}</td>
		</tr>
		{/if}
		{if condition="($detail.invoice_status == 1) AND ($uid == $detail.check_admin_id)"}
		<tr>
			<td class="layui-td-gray">选择开票人<span style="color: red">*</span></td>
			<td>
				<form class="layui-form">
				<select name="open_admin_id">
					<option value="">请选择发票开具人</option>
					{volist name=":get_check_user(4)" id="vo"}
						<option value="{$vo.uid}">{$vo.user}</option>
					{/volist}
				</select>
				</form>
			</td>
			<td colspan="4">	
				<button class="layui-btn layui-btn-danger" lay-event="checkno">审核不通过</button>
				<button class="layui-btn" lay-event="checkok">审核通过</button>
			</td>
		</tr>
		{/if}
	</table>
	<div class="layui-form-item" style="padding-top:10px;">
		<input name="id" id="id" type="hidden" value="{$detail.id}">
		{if condition="($detail.invoice_status == 0) AND ($uid == $detail.admin_id)"}
		<a class="layui-btn" href="/home/invoice/add?id={$detail.id}">编辑</a>
		{/if}
		{if condition="($detail.invoice_status == 2) AND ($uid == $detail.open_admin_id)"}
		<button class="layui-btn" lay-event="payed">开票确认</button>
		{/if}
	</div>
</div>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
function init(layui) {	
	$('.body-content').on('click', '[lay-event="checkok"]', function () {
	    var id=$('#id').val();
		var open_admin=$('[name="open_admin_id"]').val();
		if(open_admin == ''){
			layer.msg('请选择发票开具人');
			return false;
		}
		layer.confirm('确定审核通过该发票申请?', {icon: 3, title:'提示'}, function(index){
			$.ajax({
				url: "/home/invoice/check",
				data:{id:id,invoice_status:2,open_admin_id:open_admin},
				success:function(res){
					layer.msg(res.msg);
					if(res.code==0){
						parent.tableIns.reload();
						window.setTimeout(function(){
							location.reload();
						},1200)	
					}
				}
			})
		})
		return false;
	});

	$('.body-content').on('click', '[lay-event="checkno"]', function () {
		var id=$('#id').val();
		layer.confirm('确定拒绝该发票申请?', {icon: 3, title:'提示'}, function(index){
			layer.prompt({title: '拒绝的理由', formType: 3,value :''}, function(text, index){
				if(text ==''){
					layer.msg('请输入拒绝的理由');
					return false;
				}
				$.ajax({
					url: "/home/invoice/check",
					data:{id:id,invoice_status:0,check_remark:text},
					success:function(res){
						layer.msg(res.msg);
						if(res.code==0){
							parent.tableIns.reload();
							window.setTimeout(function(){
								location.reload();
							},1200)	
						}
					}
				})
				layer.closeAll();
			})
		})
	})
	
	$('.body-content').on('click', '[lay-event="payed"]', function () {
		var id=$('#id').val();
		layer.confirm('确定已经开具发票?', {icon: 3, title:'提示'}, function(index){
			layer.prompt({title: '输入发票号码', formType: 3,value :''}, function(text, index){
				if(text ==''){
					layer.msg('请输入发票号码');
					return false;
				}
				$.ajax({
					url: "/home/invoice/check",
					data:{id:id,invoice_status:3,code:text},
					success:function(res){
						layer.msg(res.msg);
						if(res.code==0){
							parent.tableIns.reload();
							window.setTimeout(function(){
								location.reload();
							},1200)	
						}
					}
				})
			})
		})
	})
}
</script>
{include file="common/layui" base='base' extend="[]" callback="init" /}
{/block}
<!-- /脚本 -->